package com.zn.controller;

import com.zn.pojo.RecordElement;
import com.zn.pojo.ServiceRecord;
import com.zn.pojo.UserRecord;
import com.zn.service.ServiceRecordService;
import com.zn.service.UserRecordService;
import com.zn.tools.MyTools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Description
 * @Author zhaoning
 * @Date 2024/7/20
 */

@Slf4j
@RestController
public class HistoryController {
    @Autowired
    private ServiceRecordService serviceRecordService;

    @Autowired
    private UserRecordService userRecordService;

    @ResponseBody
    @GetMapping("/history")
    public List<RecordElement> list(@RequestParam Integer id) {


        List<RecordElement> recordElementList = null;
        List<ServiceRecord> serviceRecordList = serviceRecordService.selectById(id);
        List<UserRecord> userRecordList = userRecordService.selectById(id);

        recordElementList = MyTools.getMessages(userRecordList, serviceRecordList);
        Collections.sort(recordElementList);

        return recordElementList;
    }
}
